const app = getApp();
var util = require('../../utils/util.js');
var applet_park_api_url = app.globalData.applet_park_api_url;
var applet_park_api_url_imgUrl = app.globalData.applet_park_api_url_imgUrl;
const {
  requestDataparams
} = require('../../utils/request.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl:applet_park_api_url_imgUrl,
    orderStatue: '', //订单状态
    orderType: '',
    lists:[],

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData()
  },
  changeTip(e){//订单类型
      this.setData({
        orderType: e.currentTarget.dataset.index
      })
      this.getData()
  },
  changeTab(e){//订单状态
    this.setData({
      orderStatue: e.currentTarget.dataset.index
    })
    this.getData()
  },
  getData(){
    var  that =this;
    wx.showLoading({
      title: '加载中',
    });
     requestDataparams('/api/orders',{ orderState: that.data.orderStatue,orderType: that.data.orderType}, 'GET','json').then(response=>{
                   //
                  
                  if(response.data.code == 0){
                    var datas = response.data.data;
                    for(var i=0;i<datas.length;i++){
                      datas[i].amount = parseInt(datas[i].amount)/100;//金额处理
                      if(datas[i].orderType == '01'){//食堂
                         datas[i].restaurant.images = datas[i].restaurant.images.split(',')[0];//图片
                      }
                      if(datas[i].orderType == '02'){//会议
                        datas[i].appointmentStartTime = datas[i].appointmentStartTime.substring(0,16);
                        datas[i].appointmentEndTime = datas[i].appointmentEndTime.substring(10,16);
                     }
                     if(datas[i].orderType == '05'){//会议
                        if(datas[i].place == '1'){
                          datas[i].placeName = '头部';
                        }else if(datas[i].place == '2'){
                          datas[i].placeName = '热门活动';
                        }else{
                          datas[i].placeName = '其他';
                        }
                        
                     }
                    }
                   this.setData({
                      lists: response.data.data
                   })
                  }else{
                    wx.showToast({
                      title: '失败',
                      icon:'none'
                    })
                  }
                  wx.hideLoading()
          })
  },
  cancleOrder(e) {//取消食堂订单
    var id = e.currentTarget.dataset.id;
     requestDataparams('/api/restaurantOrders',{ orderNo: id,status: 6 }, 'PUT','json').then(response=>{
                   
                  if(response.data.code == 0){
                    
                  }else{
                    wx.showToast({
                      title: '失败',
                      icon:'none'
                    })
                  }
                  wx.hideLoading()
          })
  },
  gorestaurantevaluation(e){//食堂评价
        var orderNo = e.currentTarget.dataset.id;
        var restaurantId = e.currentTarget.dataset.restaurantid;
        wx.navigateTo({
          url: "../../pages/restaurantevaluation/restaurantevaluation?orderNo=" + orderNo+ '&restaurantId='+restaurantId
        })
  },
  enterDetails(e){//跳转到详情  
    var orderType = e.currentTarget.dataset.ordertype;
    var id =  e.currentTarget.dataset.id;
    var item ='';
    if(e.currentTarget.dataset.item){
       item = e.currentTarget.dataset.item;
    }
    var currentCarNumber='';
    if(e.currentTarget.dataset.currentcarnumber){
      currentCarNumber = e.currentTarget.dataset.currentcarnumber;
    }
    var currentTimer = '';
    if(e.currentTarget.dataset.currenttimer){
      currentTimer = e.currentTarget.dataset.currenttimer;
    }
    var contactName = '';
    if(e.currentTarget.dataset.contactname){
      contactName = e.currentTarget.dataset.contactname;
    }
    var contactPhone = '';
    if(e.currentTarget.dataset.contactphone){
      contactPhone = e.currentTarget.dataset.contactphone;
    }
    var currentCarInfo = {};
    if(e.currentTarget.dataset.currentCarInfo){
      var carinfo = e.currentTarget.dataset.currentCarInfo;
      currentCarInfo.price = parseInt(carinfo.amount)/100;
      currentCarInfo.carNumber = carinfo.carNum;
      currentCarInfo.area = carinfo.carArea;

    }
   
    
    if(e.currentTarget.dataset.ispay){
      var pay =  e.currentTarget.dataset.ispay;
    }
    //03.房屋租赁、04.停车、05.移动端发布、06.车位租赁、07.参加付费活动、08.缴纳水费、09.缴纳电费、10.缴纳物业费
    switch(orderType){
      case '07': //参加付费活动
           wx.navigateTo({
             url: '../../packageC/pages/parkActivityDetalis/parkActivityDetalis?id='+id+'&isPay='+pay,
           })
        break;
        case '06': //车位租赁
        wx.navigateTo({
          url: '../../packageF/pages/carLeaseDetail/carLeaseDetail?item='+item+'&isPay='+pay+'&id='+id,
        })
     break;
      case '05': //移动端发布
        wx.navigateTo({
          url: '../../packageD/pages/mobileinformation/mobileinformation?id='+id,
        })
      break;
      case '02': //跳转会议室订单详情
        wx.navigateTo({
          url: '../../packageA/pages/MeetingDetail/MeetingDetail?conferenceRoomId='+id,
        })
      break;
      case '01': //跳转食堂订单详情
        wx.navigateTo({
          url: "../../pages/orderDetails_canteen/orderDetails_canteen?orderNo=" + id
        })
    break;
      default:
        break;
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})